﻿@model TS2015.ModelPopup

@using (Ajax.BeginForm(@Model.actionName, @Model.controllerName, new AjaxOptions() { HttpMethod = "POST" }, new { enctype = "multipart/form-data" }))
{
    @Html.ValidationSummary(true)
    @Html.AntiForgeryToken()

    <div class="modal fade" id="myModal" role="dialog" aria-labelledby="myModalLabel" aria-hidden="false">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title" id="myModalLabel">Nhập dữ liệu bằng Excel</h4>
                </div>
                <div class="modal-body" id="update">                  
                    <div class="form-group">
                        <input name="FileImport" type="file" class="form-control" />
                    </div>
                    <div class="modal-footer">
                        <button type="submit" id="btAccept" class="btn btn-danger">Thực hiện</button>
                        <button type="button" class="btn btn-danger" data-dismiss="modal" id="cancel">Hủy</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
}
 @*<div class="modal hide fade" id="myModalError">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="myModalLabel"><i class="glyphicon glyphicon-warning-sign"></i>Lỗi:</h4>
            </div>
            <div class="modal-body">
                    <table class="table table-bordered table-striped no-m">
                        <thead>
                            <tr>
                                <th>#</th>
                                <th>First Name</th>
                                <th>Last Name</th>
                                <th>Username</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr></tr>
                        </tbody>
                    </table>
            </div>
        </div>
    </div>
</div>*@

<script src="~/Scripts/jquery.form.min.js"></script>

<script type="text/javascript">
    (function ()
    {
        $('form').ajaxForm({                    
            complete: function (xhr)
            {
                var out = JSON.parse(xhr.responseText)

                if (out.State == true)
                {
                    var notification = $("#notification").kendoNotification().data("kendoNotification");
                    notification.show(out.Message, "info");
                    $('form').trigger("reset");
                    $('#cancel').click();

                    var grid = $("#griddata").data("kendoGrid");
                    var data = grid.dataSource;
                    data.read();
                }
                else
                {
                    var b = "";
                    var count = 0;
                    $.each(out.Message, function (index, itemData) {
                        count += 1;
                        b += count + ') ' + itemData.Text + '\n';
                    })
                    alert(b);
                    $('form').trigger("reset");
                    $('#cancel').click();
                }
                    
            }
        });

    })();

</script>
